#include "sys.h"
static void uart1_ini(void);

void sys_ini(void)
{
uart1_ini();
}
void uart1_ini(void)
{
volatile uint32_t i;	
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

//////////////////////////////////////////////////////////////////////GPIO
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

GPIO_InitStructure.GPIO_Pin 			= GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed			= GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode 			= GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);			//UART1_TX PA9		推挽复用输出

GPIO_InitStructure.GPIO_Pin 			= GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed			= GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode 			= GPIO_Mode_IN_FLOATING;
//GPIO_InitStructure.GPIO_Mode 			= GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);			//UART1_RX PA10		带上拉输入		
	
//////////////////////////////////////////////////////////////////////寄存器
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); 

USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_Init(USART1, &USART_InitStructure);
/*
i = USART_GetFlagStatus(USART1, USART_FLAG_TXE);
if(i)
	{
	USART_ClearITPendingBit(USART1,USART_IT_TXE);	
	}
*/
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
//USART_ITConfig(USART1, USART_IT_TC,  ENABLE);
USART_Cmd(USART1, ENABLE);	

//////////////////////////////////////////////////////////////////////配置中断
  /* Configure the NVIC Preemption Priority Bits */  
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
  
  /* Enable the USARTy Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn ;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
////////////////////////////////////////////////////////配置变量
}



